import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";

/**
 * model 平台级日历定义
 * @date: 2018-7-10
 */
import { getResponse, createPagination } from 'utils/utils';
import { queryIdpValue } from 'cpaas-front/lib/services/api';
import { searchCalendar as _searchCalendar, addCalendar as _addCalendar, updateCalendar as _updateCalendar, searchHolidays as _searchHolidays, searchWeekdays as _searchWeekdays, searchCalendarDetail as _searchCalendarDetail, updateWeekday as _updateWeekday, addHoliday as _addHoliday, deleteHoliday, updateHoliday as _updateHoliday } from "../services/calendarService";
export default {
  namespace: 'calendar',
  state: {
    calendarList: [],
    // 日历数据列表
    pagination: {},
    // 分页器
    calendarDetail: {},
    holidays: {},
    // 公共假期
    weekdays: [],
    // 工作日
    holidayType: [] // 公休假期类型

  },
  effects: {
    searchHolidayType: /*#__PURE__*/_regeneratorRuntime.mark(function searchHolidayType(_, _ref) {
      var call, put, result, data;
      return _regeneratorRuntime.wrap(function searchHolidayType$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              call = _ref.call, put = _ref.put;
              _context.next = 3;
              return call(queryIdpValue, 'CPFM.HOLIDAY_TYPE');

            case 3:
              result = _context.sent;
              data = getResponse(result);

              if (!data) {
                _context.next = 8;
                break;
              }

              _context.next = 8;
              return put({
                type: 'updateState',
                payload: {
                  holidayType: result
                }
              });

            case 8:
            case "end":
              return _context.stop();
          }
        }
      }, searchHolidayType);
    }),
    // 获取日历列表
    searchCalendar: /*#__PURE__*/_regeneratorRuntime.mark(function searchCalendar(_ref2, _ref3) {
      var payload, call, put, result;
      return _regeneratorRuntime.wrap(function searchCalendar$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              payload = _ref2.payload;
              call = _ref3.call, put = _ref3.put;
              _context2.t0 = getResponse;
              _context2.next = 5;
              return call(_searchCalendar, payload);

            case 5:
              _context2.t1 = _context2.sent;
              result = (0, _context2.t0)(_context2.t1);

              if (!result) {
                _context2.next = 10;
                break;
              }

              _context2.next = 10;
              return put({
                type: 'updateState',
                payload: {
                  pagination: createPagination(result),
                  calendarList: result.content
                }
              });

            case 10:
            case "end":
              return _context2.stop();
          }
        }
      }, searchCalendar);
    }),
    // 获取日历详情
    searchCalendarDetail: /*#__PURE__*/_regeneratorRuntime.mark(function searchCalendarDetail(_ref4, _ref5) {
      var payload, call, put, result;
      return _regeneratorRuntime.wrap(function searchCalendarDetail$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              payload = _ref4.payload;
              call = _ref5.call, put = _ref5.put;
              _context3.t0 = getResponse;
              _context3.next = 5;
              return call(_searchCalendarDetail, payload);

            case 5:
              _context3.t1 = _context3.sent;
              result = (0, _context3.t0)(_context3.t1);

              if (!result) {
                _context3.next = 10;
                break;
              }

              _context3.next = 10;
              return put({
                type: 'updateState',
                payload: {
                  calendarDetail: result
                }
              });

            case 10:
            case "end":
              return _context3.stop();
          }
        }
      }, searchCalendarDetail);
    }),
    // 获取公共假期信息
    searchHolidays: /*#__PURE__*/_regeneratorRuntime.mark(function searchHolidays(_ref6, _ref7) {
      var payload, call, put, result;
      return _regeneratorRuntime.wrap(function searchHolidays$(_context4) {
        while (1) {
          switch (_context4.prev = _context4.next) {
            case 0:
              payload = _ref6.payload;
              call = _ref7.call, put = _ref7.put;
              _context4.t0 = getResponse;
              _context4.next = 5;
              return call(_searchHolidays, payload);

            case 5:
              _context4.t1 = _context4.sent;
              result = (0, _context4.t0)(_context4.t1);

              if (!result) {
                _context4.next = 10;
                break;
              }

              _context4.next = 10;
              return put({
                type: 'updateState',
                payload: {
                  holidays: result
                }
              });

            case 10:
            case "end":
              return _context4.stop();
          }
        }
      }, searchHolidays);
    }),
    // 获取工作日信息
    searchWeekdays: /*#__PURE__*/_regeneratorRuntime.mark(function searchWeekdays(_ref8, _ref9) {
      var payload, call, put, result;
      return _regeneratorRuntime.wrap(function searchWeekdays$(_context5) {
        while (1) {
          switch (_context5.prev = _context5.next) {
            case 0:
              payload = _ref8.payload;
              call = _ref9.call, put = _ref9.put;
              _context5.t0 = getResponse;
              _context5.next = 5;
              return call(_searchWeekdays, payload);

            case 5:
              _context5.t1 = _context5.sent;
              result = (0, _context5.t0)(_context5.t1);

              if (!result) {
                _context5.next = 10;
                break;
              }

              _context5.next = 10;
              return put({
                type: 'updateState',
                payload: {
                  weekdays: result
                }
              });

            case 10:
            case "end":
              return _context5.stop();
          }
        }
      }, searchWeekdays);
    }),
    // 新增日历信息
    addCalendar: /*#__PURE__*/_regeneratorRuntime.mark(function addCalendar(_ref10, _ref11) {
      var payload, call, result;
      return _regeneratorRuntime.wrap(function addCalendar$(_context6) {
        while (1) {
          switch (_context6.prev = _context6.next) {
            case 0:
              payload = _ref10.payload;
              call = _ref11.call;
              _context6.next = 4;
              return call(_addCalendar, payload);

            case 4:
              result = _context6.sent;
              return _context6.abrupt("return", getResponse(result));

            case 6:
            case "end":
              return _context6.stop();
          }
        }
      }, addCalendar);
    }),
    // 更新日历信息
    updateCalendar: /*#__PURE__*/_regeneratorRuntime.mark(function updateCalendar(_ref12, _ref13) {
      var payload, call, result;
      return _regeneratorRuntime.wrap(function updateCalendar$(_context7) {
        while (1) {
          switch (_context7.prev = _context7.next) {
            case 0:
              payload = _ref12.payload;
              call = _ref13.call;
              _context7.next = 4;
              return call(_updateCalendar, payload);

            case 4:
              result = _context7.sent;
              return _context7.abrupt("return", getResponse(result));

            case 6:
            case "end":
              return _context7.stop();
          }
        }
      }, updateCalendar);
    }),
    // 新增公休假期
    addHoliday: /*#__PURE__*/_regeneratorRuntime.mark(function addHoliday(_ref14, _ref15) {
      var payload, call, result;
      return _regeneratorRuntime.wrap(function addHoliday$(_context8) {
        while (1) {
          switch (_context8.prev = _context8.next) {
            case 0:
              payload = _ref14.payload;
              call = _ref15.call;
              _context8.next = 4;
              return call(_addHoliday, payload);

            case 4:
              result = _context8.sent;
              return _context8.abrupt("return", getResponse(result));

            case 6:
            case "end":
              return _context8.stop();
          }
        }
      }, addHoliday);
    }),
    // 更新公休假期
    updateHoliday: /*#__PURE__*/_regeneratorRuntime.mark(function updateHoliday(_ref16, _ref17) {
      var payload, call, result;
      return _regeneratorRuntime.wrap(function updateHoliday$(_context9) {
        while (1) {
          switch (_context9.prev = _context9.next) {
            case 0:
              payload = _ref16.payload;
              call = _ref17.call;
              _context9.next = 4;
              return call(_updateHoliday, payload);

            case 4:
              result = _context9.sent;
              return _context9.abrupt("return", getResponse(result));

            case 6:
            case "end":
              return _context9.stop();
          }
        }
      }, updateHoliday);
    }),
    // 更新工作日
    updateWeekday: /*#__PURE__*/_regeneratorRuntime.mark(function updateWeekday(_ref18, _ref19) {
      var payload, call, result;
      return _regeneratorRuntime.wrap(function updateWeekday$(_context10) {
        while (1) {
          switch (_context10.prev = _context10.next) {
            case 0:
              payload = _ref18.payload;
              call = _ref19.call;
              _context10.next = 4;
              return call(_updateWeekday, payload);

            case 4:
              result = _context10.sent;
              return _context10.abrupt("return", getResponse(result));

            case 6:
            case "end":
              return _context10.stop();
          }
        }
      }, updateWeekday);
    }),
    // 批量删除公休假期
    deleteHolidays: /*#__PURE__*/_regeneratorRuntime.mark(function deleteHolidays(_ref20, _ref21) {
      var payload, call, result;
      return _regeneratorRuntime.wrap(function deleteHolidays$(_context11) {
        while (1) {
          switch (_context11.prev = _context11.next) {
            case 0:
              payload = _ref20.payload;
              call = _ref21.call;
              _context11.next = 4;
              return call(deleteHoliday, payload);

            case 4:
              result = _context11.sent;
              return _context11.abrupt("return", getResponse(result));

            case 6:
            case "end":
              return _context11.stop();
          }
        }
      }, deleteHolidays);
    })
  },
  reducers: {
    updateState: function updateState(state, _ref22) {
      var payload = _ref22.payload;
      return _objectSpread(_objectSpread({}, state), payload);
    }
  }
};